package cn.tedu.web;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AddCookieServlet
 */
public class AddCookieServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//利用response下发Cookie到浏览器
		//创建Cookie, Cookie中的信息需要编码
		Cookie c1=new Cookie("msg", URLEncoder.encode("Hello Word!", "utf-8"));
		Cookie c2=new Cookie("text", URLEncoder.encode("你好 Word!", "utf-8"));
		//设置过期时间 ,单位秒
		c2.setMaxAge(60*60*24);
		//利用response下发Cookie
		response.addCookie(c1);
		response.addCookie(c2);
		
		response.setContentType("text/html;charset=UTF-8");
		response.getWriter().println("OK");
	}

}
